import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xin_nuo_pda/utils/MyDateUtils.dart';
import 'package:xin_nuo_pda/utils/string_extension.dart';
import 'package:xin_nuo_pda/values/colors.dart';
import 'package:xin_nuo_pda/views/TextView.dart';
import 'package:xin_nuo_pda/views/edittext/ClearBorderEditText.dart';
import 'package:xin_nuo_pda/views/edittext/TitleEditText.dart';

import 'QaConfirmController.dart';

class QaConfirmPage extends StatelessWidget {
  final controller = Get.put(QaConfirmController());
  final state = Get.find<QaConfirmController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("QA确认"),
        ),
        body: SingleChildScrollView(
          child: Container(
            child: Column(children: [
              GetBuilder<QaConfirmController>(
                  builder: (controller) => Column(
                        children: [
                          TextView("设备ID:",
                              state.repairInfoEntity?.EQUIPMENTID ?? ''),
                          SizedBox(
                            height: 1,
                          ),
                          TextView(
                              "报修人:",
                              state.repairInfoEntity?.TROUBLEREPORTERNAME ??
                                  ''),
                          SizedBox(
                            height: 1,
                          ),
                          TextView("故障描述:",
                              state.repairInfoEntity?.TROUBLECOMMENT ?? ''),
                          SizedBox(
                            height: 1,
                          ),
                          TextView("报修时间:",
                              state.repairInfoEntity?.TROUBLETIME ?? ''),
                          SizedBox(
                            height: 1,
                          ),
                          TextView("报修备注:",
                              state.repairInfoEntity?.TROUBLEREASON ?? ''),
                          SizedBox(
                            height: 1,
                          ),
                          Container(
                            color: Colors.white,
                            padding: EdgeInsets.all(8),
                            alignment: Alignment.centerLeft,
                            child: Text(
                              "QA确认信息",
                              style: TextStyle(
                                  fontWeight: FontWeight.bold, fontSize: 16),
                            ),
                          ),
                          SizedBox(
                            height: 1,
                          ),
                          TitleEditText(
                            'QA确认人*：',
                            '请输入QA确认人',
                            (value) {},
                            isScan: false,
                            controller: state.userController,
                          ),
                          SizedBox(
                            height: 1,
                          ),
                          GetBuilder<QaConfirmController>(
                            builder: (controller) => Container(
                                padding: EdgeInsets.fromLTRB(12, 8, 12, 8),
                                color: Colors.white,
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: Text(
                                        "确认时间*:",
                                        style: TextStyle(
                                            color: theme_blue.toColor()),
                                      ),
                                      flex: 3,
                                    ),
                                    Expanded(
                                        flex: 7,
                                        child: Material(
                                          child: Ink(
                                            child: InkWell(
                                              onTap: () {
                                                MyDateUtils.showDateTime(context,
                                                    (date) {
                                                  controller
                                                      .updateSelectDate(date);
                                                },
                                                    currentTime:
                                                        state.selectDate);
                                              },
                                              child: Container(
                                                alignment: Alignment.centerLeft,
                                                padding:
                                                    EdgeInsets.only(left: 8),
                                                height: 36,
                                                decoration: BoxDecoration(
                                                    border: new Border.all(
                                                        width: 1.0,
                                                        color: Colors.grey),
                                                    borderRadius:
                                                        BorderRadius.all(
                                                            Radius.circular(
                                                                8))),
                                                child: Row(
                                                  children: [
                                                    Expanded(
                                                        child: Text(
                                                          state.selectDate.year
                                                                  .toString() +
                                                              "年" +
                                                              state.selectDate
                                                                  .month
                                                                  .toString() +
                                                              "月" +
                                                              state.selectDate
                                                                  .day
                                                                  .toString() +
                                                              "日"+
                                                              state.selectDate.hour
                                                                  .toString() +
                                                              '时' +
                                                              state.selectDate.minute
                                                                  .toString() +
                                                              '分',
                                                        ),
                                                        flex: 1),
                                                    Icon(
                                                      Icons.arrow_forward_ios,
                                                      size: 16,
                                                    ),
                                                    SizedBox(
                                                      width: 4,
                                                    )
                                                  ],
                                                ),
                                              ),
                                            ),
                                          ),
                                        ))
                                  ],
                                )),
                            id: state.dateChooseId,
                          ),
                          SizedBox(
                            height: 1,
                          ),
                          Container(
                              padding: EdgeInsets.fromLTRB(12, 8, 12, 8),
                              color: Colors.white,
                              child: Row(
                                children: [
                                  Expanded(
                                    child: Text(
                                      "QA说明:",
                                      style: TextStyle(
                                          color: theme_blue.toColor()),
                                    ),
                                    flex: 3,
                                  ),
                                  Expanded(
                                      flex: 7,
                                      child: ClearBorderEditText(
                                        "请填写QA说明",
                                        (value) {},
                                        controller: state.contentController,
                                      ))
                                ],
                              )),
                          SizedBox(
                            height: 8,
                          ),
                          ButtonBar(
                            alignment: MainAxisAlignment.spaceEvenly,
                            children: [
                              Container(
                                height: 32,
                                child: ElevatedButton(
                                  onPressed: () {
                                    controller.repairHandler('QA-IDLE');
                                  },
                                  child: Text("完成转生产"),
                                ),
                              ),
                              Container(
                                height: 32,
                                child: ElevatedButton(
                                  onPressed: () {
                                    controller.repairHandler('QA-REPAIR');
                                  },
                                  child: Text("拒绝转设备"),
                                ),
                              )
                            ],
                          ),
                          SizedBox(
                            height: 8,
                          ),
                          // Container(
                          //   color: line_gray.toColor(),
                          //   child: DefaultTabController(
                          //     length: 3,
                          //     child: Column(
                          //       children: [
                          //         TabBar(
                          //           controller: state.tabController,
                          //           labelColor: theme_blue.toColor(),
                          //           indicatorColor: theme_blue.toColor(),
                          //           tabs: [
                          //             Tab(text: '报修信息'),
                          //             Tab(text: '维修信息'),
                          //             Tab(text: 'PE确认信息'),
                          //           ],
                          //         ),
                          //       ],
                          //     ),
                          //   ),
                          // ),
                          // Offstage(
                          //   child: getAskInfo(context),
                          //   offstage: state.idx != 0,
                          // ),
                          // Offstage(
                          //   child: getRepairInfo(context),
                          //   offstage: state.idx != 1,
                          // ),
                          // Offstage(
                          //   child: getPeInfo(context),
                          //   offstage: state.idx != 2,
                          // )
                        ],
                      )),
            ]),
          ),
        ));
  }

}
